<template>
    <div>
        <Modal v-model="showAdd" @on-ok="save" ok-text="保存" :closable='false' :mask-closable=true :width="600">
            <h3 slot="header" style="color:#2D8CF0">请填写个人史情况</h3>
            <Row>
                <Col span="22" offset="1">
                    <Form label-position="top">
                        <FormItem label="是否哺乳期">
                            <RadioGroup v-model="formItem.isLactation">
                                <Radio label="0">
                                    <span>是</span>
                                </Radio>
                                <Radio label="1">
                                    <span>不是</span>
                                </Radio>
                                <Radio label="2">
                                    <span>不清楚</span>
                                </Radio>
                            </RadioGroup>
                        </FormItem>
                        <FormItem label="是否妊娠期">
                            <RadioGroup v-model="formItem.isGestation">
                                <Radio label="0">
                                    <span>是</span>
                                </Radio>
                                <Radio label="1">
                                    <span>不是</span>
                                </Radio>
                                <Radio label="2">
                                    <span>不清楚</span>
                                </Radio>
                            </RadioGroup>
                        </FormItem>
                        <FormItem label="是否抽烟">
                            <RadioGroup v-model="formItem.isSmoke">
                                <Radio label="0">
                                    <span>是</span>
                                </Radio>
                                <Radio label="1">
                                    <span>不是</span>
                                </Radio>
                                <Radio label="2">
                                    <span>不清楚</span>
                                </Radio>
                            </RadioGroup>
                        </FormItem>
                        <FormItem label="是否怀孕或哺乳">
                            <RadioGroup v-model="formItem.isPregnancy">
                                <Radio label="0">
                                    <span>是</span>
                                </Radio>
                                <Radio label="1">
                                    <span>不是</span>
                                </Radio>
                                <Radio label="2">
                                    <span>不清楚</span>
                                </Radio>
                            </RadioGroup>
                        </FormItem>
                        <FormItem label="其他：">
                            <Input v-model="formItem.otherDetails" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入内容..."></Input>
                        </FormItem>
                        <FormItem>
                            <p slot="label">
                                生活习惯及心理问卷 <a href="#" @click="doQuest">[开始做问卷]</a>
                            </p>
                            <RadioGroup v-model="formItem.resultType">
                                <Row>
                                    <Col>
                                        <Radio label="0">
                                            <span>治疗时应尽可能详细告知各种治疗风险并签订知情同意书</span>
                                        </Radio>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col>
                                        <Radio label="1">
                                            <span>治疗时要进行必要的沟通</span>
                                        </Radio>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col>
                                        <Radio label="2">
                                            <span>比较理想的治疗患者</span>
                                        </Radio>
                                    </Col>
                                </Row>
                            </RadioGroup>
                        </FormItem>
                    </Form>
                </Col>
            </Row>
        </Modal>
        <Modal v-model="showQuest" @on-ok="submit" ok-text="提交" :closable='false' :mask-closable=true :width="800">
            <h3 slot="header" style="color:#2D8CF0">请填写生活习惯及心理问卷</h3>
            <Row>
                <Col span="22" offset="1">
                    <Form label-position="top">
                        <CheckboxGroup v-model="values">
                            <FormItem label="最近是否计划外出旅游">
                                <Checkbox label="1-2">是</Checkbox>
                                <Checkbox label="2-1">否</Checkbox>
                            </FormItem>
                            <FormItem label="您准备去什么地方">
                                <Checkbox label="3-3">高海拔地区</Checkbox>
                                <Checkbox label="4-2">海滨城市</Checkbox>
                                <Checkbox label="5-1">气候干燥地区</Checkbox>
                                <Checkbox label="6-0">气候潮湿地区</Checkbox>
                                <Checkbox label="7-1">户外活动</Checkbox>
                                <Checkbox label="8-0">休闲度假</Checkbox>
                            </FormItem>
                            <FormItem label="睡眠好吗">
                                <Checkbox label="9-0">是</Checkbox>
                                <Checkbox label="10-1">还可以</Checkbox>
                                <Checkbox label="11-2">否</Checkbox>
                            </FormItem>
                            <FormItem label="时常感到">
                                <Checkbox label="12-0">很平静</Checkbox>
                                <Checkbox label="13-0">很满足</Checkbox>
                                <Checkbox label="14-2">焦虑</Checkbox>
                                <Checkbox label="15-2">紧张</Checkbox>
                                <Checkbox label="16-2">郁闷</Checkbox>
                                <Checkbox label="17-1">虚弱</Checkbox>
                                <Checkbox label="18-1">无助</Checkbox>
                                <Checkbox label="19-3">容易发脾气</Checkbox>
                            </FormItem>
                            <FormItem label="我就诊治疗是因为">
                                <Checkbox label="20-0">皮肤病</Checkbox>
                                <Checkbox label="21-1">问题皮肤</Checkbox>
                                <Checkbox label="22-0">皮肤亚健康</Checkbox>
                                <Checkbox label="23-1">皮肤不美观</Checkbox>
                                <Checkbox label="24-2">家人或朋友让我来的</Checkbox>
                                <Checkbox label="25-3">希望和明星那样</Checkbox>
                                <Checkbox label="26-2">我的缺陷太严重</Checkbox>
                                <Checkbox label="27-3">改变形象，为求职、婚姻等加分</Checkbox>
                                <Checkbox label="28-3">我是个完美主义者，希望完美</Checkbox>
                                <Checkbox label="29-1">觉得自己不够美，希望医师给我建议和治疗</Checkbox>
                            </FormItem>
                            <FormItem label="由于我皮肤的这些问题,我常常感到">
                                <Checkbox label="30-0">无所谓，很平静</Checkbox>
                                <Checkbox label="31-0">不太在意</Checkbox>
                                <Checkbox label="32-2">焦虑，不知道我该怎么办</Checkbox>
                                <Checkbox label="33-1">无助</Checkbox>
                                <Checkbox label="34-3">容易发脾气</Checkbox>
                                <Checkbox label="35-2">不喜欢外出，有些自卑</Checkbox>
                                <Checkbox label="36-2">郁闷，上帝为什么对我如此不公平</Checkbox>
                            </FormItem>
                            <FormItem label="您家人/朋友知道您要治疗吗">
                                <Checkbox label="37-1">知道</Checkbox>
                                <Checkbox label="38-2">不知道</Checkbox>
                                <Checkbox label="39-0">没有必要让他们知道，我都是自己做主的</Checkbox>
                            </FormItem>
                            <FormItem label="您接受治疗是否需要征求家人/朋友的意见">
                                <Checkbox label="40-2">通常是</Checkbox>
                                <Checkbox label="41-0">不需要</Checkbox>
                                <Checkbox label="42-1">没有必要征求他们的意见，我自己能做主的</Checkbox>
                            </FormItem>
                            <FormItem label="是否坚持皮肤护理">
                                <Checkbox label="43-2">每周2-3次</Checkbox>
                                <Checkbox label="44-1">每周1次</Checkbox>
                                <Checkbox label="45-0">每月1次</Checkbox>
                                <Checkbox label="46-0">不常做，或者没有做</Checkbox>
                            </FormItem>
                            <FormItem label="经常照镜子吗">
                                <Checkbox label="47-3">很喜欢照镜子，一有空就会照，我很欣赏镜子中的我</Checkbox>
                                <Checkbox label="48-2">每天洁面时会照镜子，并检查自己的面孔</Checkbox>
                                <Checkbox label="49-1">只是在需要的时候照镜子</Checkbox>
                                <Checkbox label="50-0">不经常照镜子</Checkbox>
                            </FormItem>
                            <FormItem label="每天用于打理自己面孔的时间">
                                <Checkbox label="51-3">超过3小时</Checkbox>
                                <Checkbox label="52-2">2-3小时</Checkbox>
                                <Checkbox label="53-1">1-2小时</Checkbox>
                                <Checkbox label="54-0">不到1小时</Checkbox>
                            </FormItem>
                        </CheckboxGroup>
                    </Form>
                </Col>
            </Row>
        </Modal>
        <iview-button
                :menuId="menuId"
                v-on="{events:events}">
        </iview-button>
        <Card v-for="(item,index) in data" :key="index" style="margin-top: 10px">
            <P>
                <Row>
                    <Col span="12">
                        调查时间：{{item.creationTime | YMDDateFormatter}}
                    </Col>
                    <Col align="right" span="12">
                        <Tag v-if="item.resultType === 0" color="red">治疗时应尽可能详细告知各种治疗风险并签订知情同意书</Tag>
                        <Tag v-if="item.resultType === 1" color="yellow">治疗时要进行必要的沟通</Tag>
                        <Tag v-if="item.resultType === 2" color="green">比较理想的治疗患者</Tag>
                    </Col>
                </Row>
            </P>
            <Row>
                <Col span="10">
                    <p>是否哺乳期</p>
                </Col>
                <Col span="4">
                    <Tag v-if="item.isLactation === 0" color="red">是</Tag>
                    <Tag v-if="item.isLactation === 1" color="green">不是</Tag>
                    <Tag v-if="item.isLactation === 2" color="warning">不清楚</Tag>
                </Col>
            </Row>
            <Row>
                <Col span="10">
                    <p>是否妊娠期</p>
                </Col>
                <Col span="4">
                    <Tag v-if="item.isGestation === 0" color="red">是</Tag>
                    <Tag v-if="item.isGestation === 1" color="green">不是</Tag>
                    <Tag v-if="item.isGestation === 2" color="warning">不清楚</Tag>
                </Col>
            </Row>
            <Row>
                <Col span="10">
                    <p>是否抽烟</p>
                </Col>
                <Col span="4">
                    <Tag v-if="item.isSmoke === 0" color="red">是</Tag>
                    <Tag v-if="item.isSmoke === 1" color="green">不是</Tag>
                    <Tag v-if="item.isSmoke === 2" color="warning">不清楚</Tag>
                </Col>
            </Row>
            <Row>
                <Col span="10">
                    <p>是否怀孕或哺乳</p>
                </Col>
                <Col span="4">
                    <Tag v-if="item.isPregnancy === 0" color="red">是</Tag>
                    <Tag v-if="item.isPregnancy === 1" color="green">不是</Tag>
                    <Tag v-if="item.isPregnancy === 2" color="warning">不清楚</Tag>
                </Col>
            </Row>
            <Row>
                <Col span="24">
                    <p>其他：{{item.otherDetails}}</p>
                </Col>
            </Row>
            <p align="right">
                <ButtonGroup>
                    <Button type="primary">
                        编辑
                    </Button>
                    <Button type="error" @click="del(item)">
                        删除
                    </Button>
                </ButtonGroup>
            </p>
        </Card>
    </div>
</template>

<script>
    import iviewTable from '@/view/common/table/Table.vue';
    import iviewButton from '@/view/common/button/Button.vue';
    export default {
        components: {
            iviewTable,
            iviewButton
        },
        props: {
        },
        computed: {
        },
        filters: {
        },
        data () {
            return {
                menuId: 615,
                showAdd: false,
                showQuest: false,
                baseURL: '/user/personal',
                selectRow: {},
                selectRows: [],
                values: [],
                data: [],
                formItem: {
                    id: '',
                    patientId: '',
                    isLactation: '',
                    isGestation: '',
                    isSmoke: '',
                    isPregnancy: '',
                    otherDetails: '',
                    resultType: '',
                    resultDetails: ''
                }
            };
        },
        methods: {
            events (item) {
                let path = item.path
                if (path === 'add') {
                    this.add()
                }
            },
            add () {
                this.formItem.id = ''
                this.$bus.init(this.formItem)
                this.showAdd = true
            },
            save () {
                this.formItem.patientId = this.$store.state.app.patientId
                let url = this.baseURL + '/saveOrUpdate'
                this.$ajax.post(url, this.formItem).then(r => {
                    let {code, msg} = r.data
                    if (code === 0) {
                        this.$bus.alert('success', '保存成功')
                        this.search()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            doQuest () {
                this.values = []
                this.showQuest = true
            },
            submit () {
                let score = 0;
                for (let i = 0; i < this.values.length; i++) {
                    let value = this.values[i].toString();
                    value = value.substring(value.indexOf('-') + 1)
                    score += parseInt(value)
                }
                if (score < 10) {
                    this.formItem.resultType = 2
                } else if (score >= 10 && score <= 20) {
                    this.formItem.resultType = 1
                } else if (score > 20) {
                    this.formItem.resultType = 0
                }
            },
            del (row) {
                this.$Modal.confirm({
                    title: '操作提示',
                    content: '<p>确认删除该条记录?</p>',
                    onOk: () => {
                        let ids = []
                        ids.push(row.id)
                        this.doDelete(ids)
                    }
                })
            },
            doDelete (ids) {
                let url = this.baseURL + '/delete'
                this.$ajax.post(url, ids).then(r => {
                    let {code, msg} = r.data
                    if (code === 0) {
                        this.$bus.alert('success', '删除成功')
                        this.search()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            refresh () {
                this.$refs.table.refresh()
            },
            changeSelect (rows) {
                this.selectRows = rows
            },
            changeTotalSize (totalSize) {
                this.pageModel.totalSize = totalSize
            },
            changePageNumber (pageNumber) {
                this.pageModel.pageNumber = pageNumber
            },
            changePageSize (pageSize) {
                this.pageModel.pageSize = pageSize
            },
            search () {
                let url = this.baseURL + '/findByPatientId/' + this.$store.state.app.patientId
                this.$ajax.get(url).then(r => {
                    let {code, data, msg} = r.data
                    if (code === 0) {
                        this.data = data
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            init () {
                this.search()
            }
        },
        mounted () {
            // this.init()
        }
    }
</script>

<style>

</style>
